package routes

import (
	"github.com/goravel/framework/contracts/route"
	"github.com/goravel/framework/facades"
	"goravel/app/http/controllers"
	"goravel/app/http/middleware"
)

func Api() {
	authController := controllers.NewAuthController()
	facades.Route().Post("api/auth/login", authController.Login)
	//注册
	facades.Route().Post("api/auth/register", authController.Register)

	facades.Route().Post("api/mini/auth/login", authController.Login)

	facades.Route().Middleware(middleware.Jwt()).Prefix("/api").Group(func(router route.Router) {
		dashboardController := controllers.NewDashboardController()
		router.Get("/dashboard", dashboardController.Index)
		userController := controllers.NewUserController()
		router.Post("/user/{id}/update_pass", userController.UpdatePassword)
		router.Get("/user/top", userController.Top)
		router.Get("/user/info", userController.Info)
		router.Post("/user", userController.Store)
		router.Get("user/search", userController.Search)
		router.Get("user/{id}/children", userController.Children)
		router.Put("user/{id}", userController.Update)
		router.Post("user/grant", userController.Grant)

		router.Get("/user", userController.Index)
		router.Get("/user/{id}", userController.Show)
		router.Delete("/user/{id}", userController.Destroy)

		//mqtt命令发送
		MQTTcommandController := controllers.NewCommandController()
		router.Post("/command/read/send", MQTTcommandController.Send)

		deviceStateController := controllers.NewDevicestateController()
		router.Get("/devicestate", deviceStateController.Index)

		readCmdController := controllers.NewReadcmdController()
		router.Get("/command", readCmdController.Index)
		router.Get("/command/list", readCmdController.List)
		router.Post("/command/{id}/rule", readCmdController.Rule)
		router.Get("/command/{id}", readCmdController.Show)

		httpController := controllers.HttpController{}
		router.Get("/command/read/options", httpController.ReadOpt)

		//设备管理
		deviceController := controllers.NewDeviceController()
		router.Get("/device", deviceController.Index)
		router.Post("device", deviceController.Store)
		router.Put("device/{id}", deviceController.Update)
		router.Delete("device/{id}", deviceController.Destroy)
		router.Get("/device/list", deviceController.List)
		//绑定运营商
		router.Post("/device/binduser", deviceController.BindUser)

		//设备轨迹
		historytrackController := controllers.NewHistorytrackController()
		router.Get("device/{id}/historytrack", historytrackController.Index)

		//设置数据
		businessdataController := controllers.NewBusinessdataController()
		router.Get("device/{id}/businessdata", businessdataController.Index)
		excelController := controllers.ExcelController{}
		router.Post("excel/upload", excelController.Upload)
		router.Get("excel/preview_read", excelController.ReadPreview)
		router.Post("excel/upload_template", excelController.Template)

		authCtrl := controllers.NewAuthController()
		router.Get("/auth/logout", authCtrl.Logout)
	})

	//小程序验证码注册
	facades.Route().Post("/api/mini/auth/register", authController.Register)
	//小程序找回密码
	facades.Route().Post("/api/mini/auth/reset", authController.Reset)
	//发送验证码
	smsController := controllers.SmsController{}
	facades.Route().Post("/api/mini/auth/validcode", smsController.ValidCode)
	facades.Route().Post("/api/mini/auth/valid_reg_code", smsController.ValidRegCode)
	facades.Route().Middleware(middleware.Jwt()).Prefix("/api/mini").Group(func(router route.Router) {
		authCtrl := controllers.NewAuthController()
		router.Get("/auth/logout", authCtrl.Logout)
	})
}
